package com.yuezhu.been;

import com.yuezhu.global.ApplicationContext;
import com.yuezhu.util.LogUtils;
import com.yuezhu.util.Preference;
import com.yuezhu.util.StringUtil;

/**
 * Created by jian on 2016/5/25.
 */
public class UserMsg {

    private static UserMsg userMsg = null;

    private String userName;
    private String userID;
    private Preference preference;
    private String authToken;
    private int level;

    public static UserMsg getInstance() {
        if (userMsg == null) {
            synchronized (UserMsg.class) {
                if (userMsg == null) {
                    userMsg = new UserMsg();
                }
            }
        }
        return userMsg;
    }
    private UserMsg() {
        preference = Preference.instance(ApplicationContext.getContext());
    }


    public String getUserName() {
        userName=preference.getString("userName");
        return userName;
    }

    public void setUserName(String userName) {
        preference.putString("userName",userName);
        this.userName = userName;
    }

    public String getUserID() {
       userID=preference.getString("userID");
        return userID;
    }

    public void setUserID(String userID) {
        preference.putString("userID",userID);
        this.userID = userID;
    }

    //退出登录
    public void quitOut(){
        userMsg.setUserID("");
        userMsg.setLevel(-1);
        userMsg.setAuthToken("");
    }

    public String getAuthToken() {
        return authToken=preference.getString("authToken");
    }

    public void setAuthToken(String authToken) {
        preference.putString("authToken",authToken);
        this.authToken = authToken;
    }

    public int getLevel() {
        return level=preference.getInt("level");
    }

    public void setLevel(int level) {
        preference.putInt("level",level);
        this.level = level;
    }
}
